<template>
  <div class="app-container">
      <div style="display:flex;margin-bottom:20px;">
      <div>
        <el-input v-model="param.search" size="small" :clearable="true" placeholder="请输入用户名" />
      </div>
      <div style="margin-left:20px">
        <el-button type="primary" size="small" icon="el-icon-search" @click="searchList">搜索</el-button>
      </div>
    </div>
    <el-table
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      border
      fit
      highlight-current-row
    >
      <el-table-column align="center" label="ID" width="95">
        <template slot-scope="scope">
          {{ scope.row.id }}
        </template>
      </el-table-column>
       <el-table-column label="申请用户ID" width="100" align="center">
        <template slot-scope="scope">
          {{ scope.row.user_id }}
        </template>
      </el-table-column>
      <el-table-column label="申请用户名" width="100" align="center">
        <template slot-scope="scope">
          {{ scope.row.user_name }}
        </template>
      </el-table-column>
      <el-table-column label="微信号" width="150" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.wechat }}</span>
        </template>
      </el-table-column>
      <el-table-column label="电话号" width="110" align="center">
        <template slot-scope="scope">
          {{ scope.row.mobile }}
        </template>
      </el-table-column>
       <el-table-column label="申请说明" width="110" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.description }}</span>
        </template>
      </el-table-column>
     <el-table-column
        class-name="status-col"
        label="参赛审核状态"
        width="120"
        align="center"
      >
        <template slot-scope="scope">
          <el-tag :type="scope.row.status | statusFilter">{{ scope.row.status == 1 ? '审核成功' : '未审核' }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column align="center" prop="created_at" label="申请时间" width="200">
        <template slot-scope="scope">
          <i class="el-icon-time" />
          <span>{{ scope.row.created_at }}</span>
        </template>
      </el-table-column>
       <el-table-column  align="center" label="操作" width="200">
        <template slot-scope="scope">
          <el-button type="primary" :disabled="scope.row.status==1" icon="el-icon-edit" size="mini" @click="CheckStu(scope.row.status == 1?2:1,scope.row.id)">审核</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      background
      :current-page="param.page"
      :page-sizes="[5, 10, 15, 20]"
      :page-size="param.limit"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      style="margin-top:20px"
    @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
</template>

<script>
import { getList } from '@/api/apply'
import { SetStu } from '@/api/apply'

export default {
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: 'success',
        draft: 'gray',
        deleted: 'danger'
      }
      return statusMap[status]
    }
  },
  data() {
    return {
      list: null,
      listLoading: true,
      role: '',
      reaviewId: '',
      param: {
        search: '',
        page: 1,
        limit: 5
      },
      formLabelWidth: '120px',
      total: 1,
      form: {
        userScore: '',
        registerId: ''
      },
      dialogFormVisible: false
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    handleSizeChange(val) {
      this.param.limit = val
      this.fetchData()
    },
    handleCurrentChange(val) {
      this.param.page = val
      this.fetchData()
    },
    searchList() {
      this.fetchData()
    },
   CheckStu(status, id,) {
      SetStu(status, id,).then((res) => {
        console.log(res, 111)
        if (res.code == 20000) {
          this.$message({
            message: res.msg,
            type: 'success'
          })
          this.fetchData()
        } else {
          this.$message({
            message: res.msg,
            type: 'error'
          })
          this.fetchData()
        }
      })
    },
    fetchData() {
      this.listLoading = true
      getList(this.param).then((response) => {
        this.list = response.data.data
        this.listLoading = false
        this.total = response.data.total
        this.role = localStorage.getItem('role')
        this.reviewer_id = localStorage.getItem('id')
        // console.log(localStorage)
      }).catch(() => {
        this.listLoading = false
      })
    }
}
}
</script>
